#include <iostream>
#include <string>
#include <sstream>
#include <memory>
#include <jsoncpp/json/json.h>
using namespace std;
using namespace Json;

int main(){
    Json::Value root;
    root["姓名"] = "张三";
    root["年龄"] = 18;
    root["成绩"].append(22);
    root["成绩"].append(50);
    root["成绩"].append(100);
    Json::StreamWriterBuilder swt;
    unique_ptr<Json::StreamWriter> ptr(swt.newStreamWriter());

    stringstream ss;
    ptr->write(root,&ss);
    cout << ss.str() << endl;

    Json::CharReaderBuilder crb;

    unique_ptr<CharReader> rp(crb.newCharReader());
    
    Json::Value tt;
    string serr;
    string my = ss.str();
    //cout << "this is my:" << my << endl;

    rp->parse(my.c_str(), my.c_str() + my.size() ,&tt, &serr);
    cout<<tt["姓名"].asString() << endl;
    cout<<tt["年龄"].asInt() << endl;
    for(int i = 0; i < tt["成绩"].size(); i++){
        cout << tt["成绩"][i].asInt();
        cout << endl;
    }
    printf("\n");


    return 0;
}
